﻿using rbac.contracts.Dto.Input;
using rbac.contracts.Dto.Output;
using rbac.contracts.Interface;
using rbac.domain.Entity;
using rbac.domain.Impl;
using rbac.domain.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace rbac.services
{
    public class PermissionService : ServiceBase, IPermissionService
    {

        IPermissionRepository _permissionRepository;

        public PermissionService(IPermissionRepository permissionRepository)
        {
            _permissionRepository = permissionRepository;
        }

        public int Add(PermissionInput permission)
        {
            var entity = _mapper.Map<Permission>(permission);
            entity.CreatedTime = DateTime.Now;
            entity.UpdateTime = DateTime.Now;
            entity.CreatedUserId = loginuserids;

            return _permissionRepository.Add(entity);
        }
        public int Update(PermissionInput permission)
        {
            return _permissionRepository.Update(_mapper.Map<Permission>(permission));
        }

        public List<PermissionOutput> GetPermiss(string permissionName)
        {
            var roles = _permissionRepository.GetPermission(permissionName).Where(x => x.IsDeleted == false);
            return _mapper.Map<List<PermissionOutput>>(roles);
        }

        public int Delete(params int[] idlist)
        {
            var loginuserid = loginuserids;

            return _permissionRepository.Delete(loginuserid, idlist);
        }
    }
}
